package calbs.socket.analysis;

import calbs.socket.pojo.req.ReqData;
import calbs.socket.pojo.req.ReqUploadLocationMsg;
import calbs.socket.tool.CHexConver;
import calbs.socket.tool.LatLngTool;

/**
 * 上传位置信息接口
 * Created by Q on 2017/8/3.
 */
public class UploadLocationAnalysisImp implements AnalysisI<ReqUploadLocationMsg> {
    @Override
    public ReqData<ReqUploadLocationMsg> analysisMsg(ReqData<ReqUploadLocationMsg> reqData){
        ReqUploadLocationMsg reqUploadLocationMsg = reqData.getBody();
        String content = reqUploadLocationMsg.getContent();
        Integer device = Integer.parseInt(content.substring(0,2*4),16);
        reqUploadLocationMsg.setDevice(device.toString());
        content = content.substring(2*4);
        Integer utcTime = Integer.parseInt(content.substring(0,2*4),16);
        reqUploadLocationMsg.setUtcTime(utcTime.toString());
        content = content.substring(2*4);
        Integer longitude = Integer.parseInt(content.substring(0,2*4),16);
        reqUploadLocationMsg.setLongitude(LatLngTool.getLatLngByOld(longitude));
        content = content.substring(2*4);
        Integer latitude = Integer.parseInt(content.substring(0,2*4),16);
        reqUploadLocationMsg.setLatitude(LatLngTool.getLatLngByOld(latitude));
        content = content.substring(2*4);
        Integer height = Integer.parseInt(content.substring(0,2*4),16);
        reqUploadLocationMsg.setHeight(LatLngTool.getHeightByOld(height));
        content = content.substring(2*4);
        Integer direction = Integer.parseInt(content.substring(0,2*2),16);
        reqUploadLocationMsg.setDirection(LatLngTool.geDirectionByOld(direction));
        content = content.substring(2*2);
        Integer speed = Integer.parseInt(content.substring(0,2*2),16);
        reqUploadLocationMsg.setSpeed(speed.toString());
        content = content.substring(2*2);
        Integer abLineID = Integer.parseInt(content.substring(0,2*4),16);
        reqUploadLocationMsg.setAbLineID(abLineID.toString());
        content = content.substring(2*4);
        Integer width = Integer.parseInt(content.substring(0,2*2),16);
        reqUploadLocationMsg.setWidth(width.toString());
        content = content.substring(2*2);
        Integer controlType = Integer.parseInt(content.substring(0,2*1),16);
        reqUploadLocationMsg.setControlType(controlType.toString());
        content= content.substring(2*1);
        Integer agMachineToolLength = Integer.parseInt(content.substring(0,2*2),16);
        String agMachineTool = CHexConver.hexStr2Str(content.substring(2*2,agMachineToolLength*2+4));
        reqUploadLocationMsg.setAgMachineTool(agMachineTool);

        content = content.substring(agMachineToolLength*2+4);
        Integer state = Integer.parseInt(content.substring(0,2*2),16);
        reqUploadLocationMsg.setState(state.toString());
        return reqData;
    }
}
